`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    17:59:37 04/19/2014 
// Design Name: 
// Module Name:    scoreDisplay 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module scoreDisplay(livesOUT,livesIN,lvOUT,levelIN,scOUT,scIN,hc,vc,blank);
    
	input [15:0] scIN; // current score
	input [2:0] livesIN; // current lives remaining
	input [2:0] levelIN; // current level
	
	input signed [11:0] hc, vc;  // current horizontal and vertical display coordinates
	input blank;			 // signal to indicate if the current pixel should be on or not
	
		// signals to indicate if VGA pixels are within desired image region
	output [4:0] scOUT; // 5 one-bit signals, one for each digit of the total score
	output [3:0] lvOUT; // to display what level you are on
	output [3:0] livesOUT; // to display your remaining lives
							  
									
		// digit image coordiantes:
								
								// score digits
	 reg signed [11:0] s1X,s2X,s3X,s4X,s5X, sY,
							   // level indicators
							 lvX1,lvX2,lvX3,lvX4, lvY,
							   // lives indicator
							 liX1,liX2,liX3,liX4, liY;	
					
	
	initial begin 
		// initial positions to place digits on screen
			s5X <= 100;	sY <= 10;
			s4X <= 116;	
			s3X <= 132;	
			s2X <= 148;		
			s1X <= 164;	
			lvX1 <= 20; lvY <= 10;
			lvX2 <= 32;
			lvX3 <= 44;
			lvX4 <= 60;
			liX1 <= 35; liY <= 28;
			liX2 <= 55;
			liX3 <= 75;
			liX4 <= 95;
	end

	//convert score to 5 digit decimal;
		wire[3:0] wTThs, wThs, wHds, wTens, wOnes;
	BCD_convert BCD(scIN, wTThs, wThs, wHds, wTens, wOnes);
	
//------------------------------------------------------------------
	//calculate on and off pixels for each digit of score
	
	VGAdigits d_05(.digitOUT(scOUT[4]), 
						.digitIN(wTThs),
						.blank(blank), 
						.hcount(hc), 
						.vcount(vc), 
						.xPos(s5X), 
						.yPos(sY));
				 
	VGAdigits d_04(.digitOUT(scOUT[3]), 
						.digitIN(wThs),
						.blank(blank), 
						.hcount(hc), 
						.vcount(vc), 
						.xPos(s4X), 
						.yPos(sY));
	
	VGAdigits d_03(.digitOUT(scOUT[2]), 
						.digitIN(wHds),
						.blank(blank), 
						.hcount(hc), 
						.vcount(vc), 
						.xPos(s3X), 
						.yPos(sY));
	
	VGAdigits d_02(.digitOUT(scOUT[1]), 
						.digitIN(wTens),
						.blank(blank), 
						.hcount(hc), 
						.vcount(vc), 
						.xPos(s2X), 
						.yPos(sY));
	
	VGAdigits d_01(.digitOUT(scOUT[0]), 
						.digitIN(wOnes),
						.blank(blank), 
						.hcount(hc), 
						.vcount(vc), 
						.xPos(s1X), 
						.yPos(sY));						
//------------------------------------------------------------------

//-----------------------------------------------------------------
	//calculate on and off pixels for current level
	
	wire [48:1] lvPixGrid1,lvPixGrid2,lvPixGrid3;  
		assign lvPixGrid1 = 48'b 000000000000100111100101100111100100110111000000;
		assign lvPixGrid2 = 48'b 000000000000010101010101010101010101001001000000;
		assign lvPixGrid3 = 48'b 000000000000110100010100110100000100110110000000;
		
		digGrid lv1(lvPixGrid1, hc, vc, blank, lvX1, lvY, lvOUT[3]);
		digGrid lv2(lvPixGrid2, hc, vc, blank, lvX2, lvY, lvOUT[2]);
		digGrid lv3(lvPixGrid3, hc, vc, blank, lvX3, lvY, lvOUT[1]);
		
			reg[3:0]levelNum;
				initial levelNum <=4'd 1;
			
			always @ (levelIN) begin
				case (levelIN)
					3'b 100: levelNum <= 4'd 3;
					3'b 010: levelNum <= 4'd 2;
					3'b 001: levelNum <= 4'd 1;
				endcase
			end
			
			VGAdigits LVL(.digitOUT(lvOUT[0]), 
							.digitIN(levelNum),
							.blank(blank), 
							.hcount(hc), 
							.vcount(vc), 
							.xPos(lvX4), 
							.yPos(lvY));		
//------------------------------------------------------------------
	
//------------------------------------------------------------------
	//calculate on and off pixels for current lives remaining
		
			wire [24:1] lifeIcon;
				assign lifeIcon = 24'b 100000111100111111011000;		

		wire life1,life2,life3,life4;

	digGrid2 LI1(lifeIcon, hc, vc, blank, liX1, liY, life1);
	digGrid2 LI2(lifeIcon, hc, vc, blank, liX2, liY, life2);
	digGrid2 LI3(lifeIcon, hc, vc, blank, liX3, liY, life3);
	digGrid2 LI4(lifeIcon, hc, vc, blank, liX4, liY, life4);
	
	assign livesOUT[3] = (life1 && (livesIN > 0));
	assign livesOUT[2] = (life2 && (livesIN > 1));
	assign livesOUT[1] = (life3 && (livesIN > 2));
	assign livesOUT[0] = (life4 && (livesIN > 3));
//------------------------------------------------------------------

	
endmodule
